package com.ewzj.bigdata.mvp.model

import android.app.Application
import com.bumptech.glide.Glide
import com.ewzj.bigdata.app.config.netmodel.CommonCache
import com.ewzj.bigdata.app.config.netmodel.CommonService
import com.ewzj.bigdata.app.extensions.getRxcache
import com.ewzj.bigdata.app.extensions.json2Body
import com.ewzj.bigdata.app.utils.FilesUtlis
import com.ewzj.bigdata.mvp.contract.CitySelectorActivityContract
import com.ewzj.bigdata.mvp.contract.DecorateContract
import com.ewzj.bigdata.mvp.contract.SettingActivityContract
import com.ewzj.bigdata.mvp.model.reqbean.ReqCityBean
import com.ewzj.bigdata.mvp.model.reqbean.ReqSearchCityBean
import com.ewzj.bigdata.mvp.model.reqbean.Reqpagebean
import com.ewzj.bigdata.mvp.model.rspbean.BaseData
import com.ewzj.bigdata.mvp.model.rspbean.CityBean
import com.ewzj.bigdata.mvp.model.rspbean.CitySearchBean
import com.google.gson.Gson
import com.jess.arms.integration.IRepositoryManager
import com.jess.arms.integration.RepositoryManager
import com.jess.arms.mvp.BaseModel
import com.jess.arms.utils.DataHelper
import com.jess.arms.utils.UiUtils
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers
import io.rx_cache2.DynamicKey
import io.rx_cache2.EvictDynamicKey
import io.rx_cache2.internal.RxCache
import timber.log.Timber
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class SettingActivityModel @Inject constructor(val application: Application,val mGson:Gson,val repositoryManager: IRepositoryManager) :BaseModel(repositoryManager),SettingActivityContract.Model{


    val service=repositoryManager.obtainRetrofitService(CommonService::class.java)
    val cache=repositoryManager.obtainCacheService(CommonCache::class.java)
    override fun getCacheFileSize(): String {
        val cache = DataHelper.getDirSize(DataHelper.getCacheFile(application))

        return FilesUtlis.formatSize(cache)
    }

    override fun clearCacheFile(): Unit {
        FilesUtlis.deleteDirectoryAllFile(DataHelper.getCacheFile(application))
        Glide.get(application).clearDiskCache()
    }

    override fun clearRxCacheFile() {
        (repositoryManager as RepositoryManager).getRxcache().evictAll().subscribe()
    }
}